package demo4接口使用;
class Money implements Cloneable{
    public int m = 19;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
class Person implements Cloneable{
    public String name;
    public  int age;

    public Money m;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
        this.m = new Money();
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Person tmp = (Person) super.clone();
        tmp.m = (Money) this.m.clone();
        return tmp;
    }
}
public class Test2 {
    public static void main(String[] args)throws CloneNotSupportedException{
        Person person1 = new Person("zhangsan",12);
        Person person2 = (Person) person1.clone();
        System.out.println(person1);
        System.out.println(person2);

        System.out.println(person1.m.m);
        System.out.println(person2.m.m);
        System.out.println("===========");
        person2.m.m = 10;
        System.out.println(person1.m.m);
        System.out.println(person2.m.m);

    }


}
